<?php
/* @var $this BackendController */
/* @var $model User */

$this->breadcrumbs=array(
	Yii::t('UserModule.base','Users')=>array('index'),
	Yii::t('UserModule.base','Manage'),
);
Yii::app()->clientScript->registerPackage('fancybox');
Yii::app()->clientScript->registerScript('search', "

$('.btn-mini').live('click',function(e){
   var userId = $(this).attr('id');
   if(userId)
   {
        $.ajax({
            url:'changestatusactive',
            data:{id:userId},
            dataType:'JSON',
            error:function(){alert('Ajax request changeStatusActive returned Error')},
            success:function(resp){
            if(resp.error)
            {
                alert(resp.error);
            }
                $.fn.yiiGridView.update('user-grid');
            }
        });

   }
});
    $(document).on('mouseenter','[data-toggle=tooltip]', function(){
        $(this).tooltip('show');
    });
    $(document).on('mouseleave','[data-toggle=tooltip]', function(){
        $(this).tooltip('hide');
    });
    $('.fancybox').fancybox();

    $('.search-button').click(function(){
        $('.search-form').toggle();
        return false;
    });
    $('.search-form form').submit(function(){
        $('#user-grid').yiiGridView('update', {
            data: $(this).serialize()
        });
        return false;
    });
");
?>

<?php $this->beginWidget('TBAlertWidget');?>
<?php $this->endWidget('TBAlertWidget');?>

<div class="panel panel-primary">
    <div class="panel-heading">
        <i class="fa fa-user"></i><span class="h4"><?php echo Yii::t('UserModule.base','Manage Users')?></span>
    </div>
    <div class="panel-body">

        <?php if(Yii::app()->user->hasFlash('message')):?>
            <div class="alert alert-danger">
                <?php echo Yii::app()->user->getFlash('message');?>
            </div>
        <?php endif;?>

<div class="search-form">
<?php $this->renderPartial('_search',array(
	'model'=>$model,
    'columnName'=>'name'
)); ?>
</div><!-- search-form -->

<?php $this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'user-grid',
    'template'=>'{items}{pager}',
	'dataProvider'=>$model->search(),
	//'filter'=>$model,
    'pager' => array('cssFile' => Yii::app()->theme->baseUrl . '/assets/gridview/pager.css'),
    'baseScriptUrl'=>Yii::app()->theme->baseUrl.'/assets/gridview',
	'columns'=>array(

        array(
            'name' => 'id',
            'type' => 'raw',
            'value'=>'CHtml::tag("span",array("class"=>"badge"),$data->id)',
            'htmlOptions' => array('style'=>'width:50px'),
        ),
        array(
            'name' => 'avatar',
            'type' => 'html',
            'value' => '$data->getImageForGrid()',
            'htmlOptions' => array('style'=>'width:40px'),
        ),
        array(
            'name' => 'name',
            'type' => 'html',
            'value' => 'CHtml::link($data->name,Yii::app()->createUrl("user/backend/update",array("id"=>$data->id)),array("title"=>Yii::t("UserModule.base","Change User Settings {name}",array("{name}"=>$data->name))))',
            'htmlOptions' => array('style'=>'width:200px'),
        ),
        array(
            'name' => 'login',
            'type' => 'raw',
            'htmlOptions' => array('style'=>'width:200px'),
        ),
        array(
            'name' => 'active',
            'type' => 'raw',
            'value' => '$data->getIsActive()',
            'htmlOptions' => array('style'=>'width:30px'),
        ),
        array(
            'name'=>'role',
            'type' => 'raw',
            'htmlOptions' => array('style'=>'width:50px'),
        ),
        array(
            'name'=>'email',
            'type'=>'raw',
            'value'=>'CHtml::tag("span",array("class"=>"label label-default font12"),$data->email)',
        ),
        array(
            'name'=>'last_login_time',
            'type'=>'raw',
            'value'=>'CHtml::tag("span",array("class"=>"label label-primary font12"),CLocale::getInstance(Yii::app()->getLocale()->id)->dateFormatter->formatDateTime(strtotime($data->last_login_time),"long","short"))',
        ),
        array(
            'name'=>'create_time',
            'type'=>'raw',
            'value'=>'CHtml::tag("span",array("class"=>"label label-primary font12"),CLocale::getInstance(Yii::app()->getLocale()->id)->dateFormatter->formatDateTime(strtotime($data->create_time),"long","short"))',
        ),
        array(
            'class'=>'CButtonColumn',
            'htmlOptions' => array('style'=>'width:150px;font-size:20px'),
            'template'=>'{email}&nbsp{view}&nbsp{update}&nbsp{delete}',
            'buttons'=>array(
                'email'=>array(
                    'label'=>'',
                    'imageUrl'=>'',
                    'url'=>'Yii::app()->createUrl("user/backend/sendemail",array("id"=>$data->id,"name"=>$data->name,"email"=>$data->email))',
                    'options'=>array('class'=>'fa fa-envelope','style'=>'padding-right:5px','data-toggle'=>'tooltip','title'=>Yii::t('UserModule.base','Send to email notification')),
                ),
                'view'=>array(
                    'label'=>'',
                    'imageUrl'=>'',
                    'options'=>array('class'=>'fa fa-eye','style'=>'padding-right:5px','data-toggle'=>'tooltip','title'=>Yii::t('UserModule.base','View')),
                ),
                'update'=>array(
                    'label'=>'',
                    'imageUrl'=>'',
                    'options'=>array('class'=>'fa fa-edit','style'=>'padding-right:5px','data-toggle'=>'tooltip','title'=>Yii::t('UserModule.base','Edit')),
                ),
                'delete'=>array(
                    'label'=>'',
                    'imageUrl'=>'',
                    'options'=>array('class'=>'fa fa-trash-o','style'=>'padding-right:5px','data-toggle'=>'tooltip','title'=>Yii::t('UserModule.base','Delete')),
                ),
            )
        ),
	),
)); ?>
    </div>
</div>